﻿@using System.Web.UI.WebControls
@using DevExpress.Web.ASPxGridView
@using DevExpress.Web.Mvc.UI
@using Dogshow.Model
@using Dogshow.Web.ViewModels.Izlozbe
@model SudijeViewModel


@Html.DevExpress().GridView(s =>
{
    s.Name = "gvSudije";
    s.Caption = "Raspored sudija po ringovima";
    s.CallbackRouteValues = new {Controller = "Izlozbe", Action = "SudijeGridViewPartial", Model.IdIzlozbe};
    s.Columns.Add(c =>
    {
        c.FieldName = "IdSudije";
        c.Caption = "Sudija";
        c.CellStyle.HorizontalAlign = HorizontalAlign.Left;
        c.SetEditItemTemplateContent((cs) => @Html.RenderPartial("_UnosSudijeComboBox", new ViewDataDictionary(DataBinder.Eval(cs.DataItem, "IdSudije"))));
        c.SetDataItemTemplateContent(cs => ViewContext.Writer.WriteLine(DataBinder.Eval(cs.DataItem, "ImeSudije")));
    });

    s.Columns.Add(c =>
    {
        c.FieldName = "Ring";
        c.Caption = "Ring";
        c.Width = Unit.Pixel(50);
        c.CellStyle.HorizontalAlign = HorizontalAlign.Center;
    });
    s.SettingsPager.PageSize = 25;
    s.Width = Unit.Pixel(400);
    s.SettingsBehavior.AllowFocusedRow = true;
    s.KeyFieldName = "IdSudije";
    
    s.SettingsBehavior.AllowClientEventsOnLoad = true;
    s.SettingsBehavior.ConfirmDelete = true;
    s.SettingsText.ConfirmDelete = "Potvrdite brisanje";
    s.SettingsText.EmptyDataRow = "Nema podataka";
    
    s.SettingsEditing.Mode = GridViewEditingMode.Inline;
    s.SettingsEditing.ShowModelErrorsForEditors = true;
    s.CommandColumn.Visible = true;
    s.CommandColumn.ButtonType = ButtonType.Image;
    
    s.CommandColumn.EditButton.Visible = true;
    s.CommandColumn.EditButton.Image.ToolTip = "Izmeni";
    s.CommandColumn.EditButton.Image.Url = @Url.Content("~/Content/images/edit.png");
    s.SettingsEditing.UpdateRowRouteValues = new { Controller = "Izlozbe", Action = "AzurirajSudijuURingu" };

    s.SettingsEditing.AddNewRowRouteValues = new { Controller = "Izlozbe", Action = "DodajSudijuURingu", Model.IdIzlozbe };
    s.SettingsEditing.NewItemRowPosition = GridViewNewItemRowPosition.Bottom;

    s.CommandColumn.Width = Unit.Pixel(80);
    s.CommandColumn.DeleteButton.Visible = true;
    s.CommandColumn.DeleteButton.Image.ToolTip = "Obriši";
    s.CommandColumn.DeleteButton.Image.Url = @Url.Content("~/Content/images/user_trash.png");
    s.SettingsEditing.DeleteRowRouteValues = new {Controller = "Izlozbe", Action = "ObrisiSudijuIRing"};

    s.CommandColumn.UpdateButton.Image.ToolTip = "Prihvati";
    s.CommandColumn.UpdateButton.Image.Url = @Url.Content("~/Content/images/ok.png");
    s.CommandColumn.CancelButton.Image.ToolTip = "Otkaži";
    s.CommandColumn.CancelButton.Image.Url = @Url.Content("~/Content/images/cancel.png");
    s.CommandColumn.SetHeaderTemplateContent(c => @Html.DevExpress().HyperLink(link =>
                                                    {
                                                        link.Name = "btnAddNew";
                                                        link.Properties.Text = "Novi unos";
                                                        link.Properties.ClientSideEvents.Click = "function(s, e){gvSudije.AddNewRow();}";
                                                    }).GetHtml());
    s.ClientSideEvents.BeginCallback = "onBeginSudijeGridViewPartialCallback";
    s.ClientSideEvents.FocusedRowChanged = "onIzabranSudija";
    
}).Bind(Model.SudijePoRingovima).GetHtml()
      